package com.xsomnus.network_programming.udp;

import java.io.IOException;
import java.net.*;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/7/24 0024 9:40
 * - 才需学也,学需静也/非淡泊无以明志，非宁静无以致远
 */
public class UDPSender {

    public static void main(String[] args) {
        try {
            String host = "255.255.255.255";
            DatagramSocket datagramSocket = new DatagramSocket();
            String data = "hello, world";
            InetAddress adds = InetAddress.getByName(host);
            DatagramPacket datagramPacket = new DatagramPacket(data.getBytes(), data.getBytes().length, adds, 9090);
            datagramSocket.send(datagramPacket);
            System.out.println("udp socket关闭");
            datagramSocket.close();
        } catch (SocketException e) {
            e.printStackTrace();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
